package controls.questions {
	
	import mx.containers.VBox;
	import mx.controls.Label;
	import mx.events.FlexEvent;
	
	/**
	 * @author Brent Kersanske
	 */ 
	public class ScenarioClass extends VBox {
		
		private var _rawText:String;
		
		public function ScenarioClass()	{
			addEventListener(FlexEvent.CREATION_COMPLETE, handleCreationComplete);
		}
		
		private function handleCreationComplete(e:FlexEvent):void {
			extrapolateLabelsFromRawText();
		}
		
		public function set rawText(rawText:String):void {
			_rawText = rawText;
		}
		
		public function get rawText():String {
			return _rawText;
		}
		
		private function extrapolateLabelsFromRawText():void {
			var labelsToAdd:Array = this.rawText.split(".");	
			labelsToAdd.pop();	
			for each(var label:String in labelsToAdd) {
				if(label.charAt(0) == " ") {
					label = label.substr(1, label.length);
				}
				createAndAddLabelChild(label);
			}
		}
		
		private function createAndAddLabelChild(text:String):void {
			var newLabel:Label = new Label();
			newLabel.styleName = "questionText";
			newLabel.text 	   = text + ".";
			addChild(newLabel);
		}
	}
}